<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>试题管理</title>
<link href="<%=request.getContextPath()%>/static/sys/user-manager/css/userList.css" rel="stylesheet" type="text/css" />
<script src="<%=request.getContextPath()%>/jquery.min.js"></script>
<script src="<%=request.getContextPath()%>/layer-2.1/layer.js"></script>
<style type="text/css">
body {
	margin-left: 3px;
	margin-top: 0px;
	margin-right: 3px;
	margin-bottom: 0px;
}
.STYLE1 {
	color: #e1e2e3;
	font-size: 12px;
}
.STYLE6 {color: #000000; font-size: 15px; }
.STYLE10 {color: #000000; font-size: 17px; }
.STYLE19 {
	color: #344b50;
	font-size: 15px;
}
.STYLE21 {
	font-size: 12px;
	color: #3b6375;
}
.STYLE22 {
	font-size: 12px;
	color: #295568;
}
#myModal{
	width: 530px;
	height:400px;
	background: #ccffff;
}
#alterUserInfoInnerBox{
	margin-left: 125px;
	font-size: 14px;
	font-family: "宋体" serif;
}
</style>
</head>
<body>
	<center>
		<h1>试题管理</h1>
	</center>
	<form id="conditionForm" name="conditionForm" action="<%=request.getContextPath()%>/teach/testquestion/QuestionServlet?command=list"
		method="post">
		题目：<input type="text" name="question" value="${conditionEntity.question}"></input>&nbsp
		题型：<select name="question_type">
			<option value="0">-全部-</option>
			<option value="1" <c:if test="${conditionEntity.question_type == 1}">selected=selected</c:if>>单选</option>
			<option value="2" <c:if test="${conditionEntity.question_type == 2}">selected=selected</c:if>>多选</option>
			<option value="3" <c:if test="${conditionEntity.question_type == 3}">selected=selected</c:if>>判断</option>
		</select>&nbsp
		所属课程：<select name="courseName"> 
				<option value="">—全部课程—</option>
                <c:forEach items="${nameList }" var="nameList" >               
				<option  value="${nameList.courseName  }">　${nameList.courseName  }　</option>
				<span id="courseName"></span>
			</c:forEach>  
			</select>&nbsp
		难度：<select name="difficulty">
			<option value="0">-全部-</option>
			<option value="1" <c:if test="${conditionEntity.difficulty == 1}">selected=selected</c:if>>低</option>
			<option value="2" <c:if test="${conditionEntity.difficulty == 2}">selected=selected</c:if>>中</option>
			<option value="3" <c:if test="${conditionEntity.difficulty == 3}">selected=selected</c:if>>较高</option>
			<option value="4" <c:if test="${conditionEntity.difficulty == 4}">selected=selected</c:if>>高</option>
		</select>&nbsp
		状态：<select name="state">
			<option value="0">-全部-</option>
			<option value="1" <c:if test="${conditionEntity.state == 1}">selected=selected</c:if>>有效</option>
			<option value="2" <c:if test="${conditionEntity.state == 2}">selected=selected</c:if>>无效</option>
		</select>
		<input type = "submit" value="查询" title="查询"></input>
	</form>
	&nbsp; &nbsp; &nbsp;
	<table width="100%" border="1" align="center" bgcolor="#a8c7ce" cellpadding="0" cellspacing="0">
		<thead>
			<tr>
				<td colspan="7" align="right"><a href="<%=request.getContextPath()%>/teach/testquestion/QuestionServlet?command=preAdd">试题新增</a></td>
			</tr>
			<tr>
		        <td width="4%" height="20" bgcolor="d3eaef" class="STYLE10"><div align="center">
		          <input type="checkbox" name="checkbox" id="checkbox" />
		        </div></td>
		        <td width="10%" height="25" bgcolor="d3eaef" class="STYLE1"><div align="center"><span class="STYLE10">题目</span></div></td>
				<td width="15%" height="25" bgcolor="d3eaef" class="STYLE10"><div align="center"><span class="STYLE10">题型</span></div></td>
		        <td width="24%" height="25" bgcolor="d3eaef" class="STYLE10"><div align="center"><span class="STYLE10">所属课程</span></div></td>
		        <td width="16%" height="25" bgcolor="d3eaef" class="STYLE10"><div align="center"><span class="STYLE10">难度</span></div></td>
		        <td width="15%" height="25" bgcolor="d3eaef" class="STYLE10"><div align="center"><span class="STYLE10">状态</span></div></td>
		        <td width="14%" height="25" bgcolor="d3eaef" class="STYLE10"><div align="center"><span class="STYLE10">操作</span></div></td>
     		 </tr>
		</thead>
		<c:forEach items="${pageModel.list }" var="list" varStatus="v">
			<tr class="autoTr" bgcolor="#FFFFFF">
				<td height="20" bgcolor="d3eaef"><div align="center">
          <input type="checkbox" name="checkbox2" id="checkbox2" />
        </div></td>
				<td height="20" bgcolor="d3eaef" class="STYLE19" align="center">${list.question}</td>
				<td height="20" bgcolor="d3eaef" class="STYLE19" align="center">
				<c:if test="${list.question_type == 1}"><font>单选题</font></c:if>
				<c:if test="${list.question_type == 2}"><font>多选题</font></c:if>
				<c:if test="${list.question_type == 3}"><font>判断题</font></c:if>
				</td>
				<td height="20" bgcolor="d3eaef" class="STYLE19" align="center">${list.courseName}</td>
				<td height="20" bgcolor="d3eaef" class="STYLE6" align="center">
					<c:if test="${list.difficulty == 1}"><font>低</font></c:if>
					<c:if test="${list.difficulty == 2}"><font>中</font></c:if>
					<c:if test="${list.difficulty == 3}"><font>较高</font></c:if>
					<c:if test="${list.difficulty == 4}"><font>高</font></c:if>
				</td>
				<td height="20" bgcolor="d3eaef" class="STYLE19" align="center" id="state${v.count}"><c:if test="${list.state == 1 }">
						<font color="green" id="state${list.id}">有效</font>
					</c:if> <c:if test="${list.state == 2 }">
						<font color="red" id="state${list.id}">无效</font>
					</c:if></td>
				<td height="20" bgcolor="d3eaef" class="STYLE6" align="center">
					<a href ="<%=request.getContextPath()%>/teach/testquestion/QuestionServlet?command=preUpdate&id=${list.id}" >详情</a>| 
					<a id="changeState${v.count }" href="javascript:;" 
					onclick ="updateState(${v.count}, ${list.id});"> 
						<c:if test="${list.state == 1 }">无效</c:if> 
						<c:if test="${list.state == 2 }">有效</c:if>
					</a>
				</td>
			</tr>
		</c:forEach>
		<tr>
			<td colspan="12" align="right">
				<a href = "javascript:;" onclick="submitCondition(${pageModel.first});">首页</a>&nbsp;
				<a href = "javascript:;" onclick="submitCondition(${pageModel.pre});">上一页</a>&nbsp;
				第<select onchange="goPage(this)">
				<script>
				var pageNo = '${pageModel.pageNo}';
				var totalPage = '${pageModel.totalPage}';
				for (var i = 1; i <= totalPage; i++) {
				if (pageNo == i) {
					document.write('<option value="' + i + '" selected="selected">' + i + '</option>');
				} else {
					document.write('<option value="' + i + '">' + i + '</option>');
						}
				}
				</script>
				</select>页
				,共${pageModel.totalPage}页&nbsp;
				<a href = "javascript:;" onclick="submitCondition(${pageModel.next});">下一页</a>&nbsp;
				<a href = "javascript:;" onclick="submitCondition(${pageModel.last});">尾页</a>&nbsp;
				共${pageModel.allRecords }条记录
			</td>
		</tr>
	</table>
</body>
<script type="text/javascript">

function submitCondition(pageNo){
	document.conditionForm.action="<%=request.getContextPath()%>/teach/testquestion/QuestionServlet?command=list&pageNo="+pageNo;
	document.conditionForm.submit();
}

function updateState(count,id){
	var xmlhttp;
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {
		  var state=xmlhttp.responseText;
		  
		  var stateId = document.getElementById("state"+count);
		  var changeStateId = document.getElementById("changeState"+count);

		  if(state==1){
			  stateId.innerHTML = "有效";
			  changeStateId.innerHTML = "无效";
		  }else if(state==2){
			  stateId.innerHTML = "无效";
			  changeStateId.innerHTML = "有效";
		  }
		  
	    }
	  }
	xmlhttp.open("get","<%=request.getContextPath()%>/teach/testquestion/QuestionServlet?command=changeState&id="+id,true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send();
}
function goPage(obj) {
	location = '<%=request.getContextPath()%>/teach/testquestion/QuestionServlet?command=list&pageNo='
				+ obj.value;
	}
</script>
</html>